﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using ChinaSoft.BLL;
using ChinaSoft.Model;
using System.Collections.Generic;

namespace Maticsoft.Web.Accounts
{
	/// <summary>
	/// SetPass 的摘要说明。
	/// </summary>
	public partial class SetPass : System.Web.UI.Page
	{

        public string strid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["currentUserID"] != null && Session["currentUserID"].ToString().Trim() != "")
                {
                    strid = Session["currentUserID"].ToString();
                    int UsersId = (Convert.ToInt32(strid));
                    ShowInfo(UsersId);
                }
            }
        }

        private void ShowInfo(int UsersId)
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_Users bll = new ChinaSoft.BLL.BLL_tb_MidSoft_Users();
            ChinaSoft.Model.Model_tb_MidSoft_Users model = bll.GetModel(UsersId);
            this.lblName.Text = model.UserAccount;
        }
		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btnUpdate_Click(object sender, System.EventArgs e)
		{
            string username = this.lblName.Text;
				string passward=Maticsoft.Common.DEncrypt.DEncrypt.MD5(this.txtOldPassword.Text.Trim(),16);

                BLL_tb_MidSoft_Users bllUsers = new BLL_tb_MidSoft_Users();
                Model_tb_MidSoft_Users modelUsers = new Model_tb_MidSoft_Users();
                List<Model_tb_MidSoft_Users> listUsers = bllUsers.GetModelList("UserAccount='" + username + "' and UserPassword='" + passward + "'");
                if (listUsers != null && listUsers.Count > 0 && listUsers[0].UsersId > 0)
                {
                    listUsers[0].UserPassword = Maticsoft.Common.DEncrypt.DEncrypt.MD5(this.txtPassword.Text.Trim(), 16);
                    if (bllUsers.Update(listUsers[0]))
                    {
                        this.lblMsg.ForeColor = Color.Blue;
                        this.lblMsg.Text = "用户信息更新成功！";
                    }
                    else
                    {
                        this.lblMsg.ForeColor = Color.Red;
                        this.lblMsg.Text = "更新用户信息发生错误！";
                    }
                }
                else
                {
                    this.lblMsg.ForeColor = Color.Red;
                    this.lblMsg.Text = "原始密码有误！";
                }
		}

		protected void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.txtPassword.Text="";
			this.txtPassword1.Text="";
		}
	}
}
